﻿using MQTTnet;
using MQTTnet.Protocol;
using MQTTnet.Server;
using System;

namespace MqttServer
{
    class Program
    {
        static void Main(string[] args)
        {

            var optionsBuilder = new MqttServerOptionsBuilder()
                .WithDefaultEndpointPort(1883)
                .WithConnectionValidator(c =>
                {
                    
                    c.ReasonCode = MqttConnectReasonCode.Success;
                })
                .WithSubscriptionInterceptor(c =>
                {
                    c.AcceptSubscription = true;
                })
                .WithApplicationMessageInterceptor(
                c =>
                {
                    c.AcceptPublish = true;
                });

            var mqttServer = new MqttFactory().CreateMqttServer();
            mqttServer.StartAsync(optionsBuilder.Build());
            mqttServer.ApplicationMessageReceivedHandler = new ApplicationMessageHandler();
            Console.ReadLine();
        }
    }
}
